Skip to content

London | 26-ITP-May | Raihan Sharif | Sprint 1 | Destructuring exercises#492

Open
RaihanSharif wants to merge 8 commits into
CodeYourFuture:mainfrom
RaihanSharif:sprint-1-desctructuring
Open

London | 26-ITP-May | Raihan Sharif | Sprint 1 | Destructuring exercises#492
RaihanSharif wants to merge 8 commits into
CodeYourFuture:mainfrom
RaihanSharif:sprint-1-desctructuring

Conversation

@RaihanSharif
Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Did all required tasks. In exercise 2, ignore the last function if you just want a minimal working solution.

@RaihanSharif RaihanSharif added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Data-Flows The name of the module. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels May 8, 2026
Copy link
Copy Markdown
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all works, but a few questions/suggestions about some details :)

// Don't change anything else.
function introduceYourself(___________________________) {
function introduceYourself({
name = "NO NAME",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to add default values here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted users to be get some feedback if some values were not supplied, rather than just leaving it blank.

I have removed it.

},
];

function logPeopleByHouse(peopleList, houseName) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These solutions work, but don't use destructuring as much as they could. Given this exercises is about destructuring, can you aim for maximum destructring?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added more destructuring, can this be considered maximum descructuring?

I prefer the previous solution in terms of readability. Though I guess if you have a lot of properties it can get tedious.

What do you think?

order.forEach((item) => {
const { quantity, itemName, unitPricePence } = item;
console.log(
`${String(quantity).padEnd(8)}${String(itemName).padEnd(20)}${((quantity * unitPricePence) / 100).toFixed(2)}`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's quite a lot of repetition with your formatting. Imagine if we start to start padding QTY by only 4 or 12 characters - you'd need to update two different places. Can you work out how to reduce that repetition?

Copy link
Copy Markdown
Author

@RaihanSharif RaihanSharif May 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of adding a reciept formatter or string building function that would take quantity, itemName, and unitPricePence, and return a formatted String for console to output. I thought this might be overkill for a simple receipt function.

Instead I just store the padding values up top as variables, so that padding can be easily adjusted, without having to touch the console log code.

console.log(`${"QTY".padEnd(8)}${"ITEM".padEnd(20)}TOTAL`);
let total = 0;
order.forEach((item) => {
const { quantity, itemName, unitPricePence } = item;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be tidier to destructure in the parameter, rather than having a named parameter and them immediately destructuring it. WDYT?

Copy link
Copy Markdown
Author

@RaihanSharif RaihanSharif May 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, just doing the destructuring in the parameter makes it easier to read and understand. Code is now changed.

@illicitonion illicitonion added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels May 14, 2026
@RaihanSharif RaihanSharif added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Data-Flows The name of the module. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants